﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ServiceInterfaces.DataContracts;
using ServiceInterfaces.ServiceInterfaces;
using System.IO;
using System.ServiceModel;

using BLL;


namespace ServiceImpl
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public  class ShopAndProductTempleteService : IShopAndProductTemplete
    {
        OrderBLL _orderBLL = new OrderBLL();
        public Dictionary<int, List<ProductTempleteInfo>> _shopProductTempleteList = new Dictionary<int, List<ProductTempleteInfo>>();//商户产品列表
        public  List<ShopInfo_Order> _shopList = new List<ShopInfo_Order>();//商户列表 


        /// <summary>
        /// 获取所有产品模版
        /// </summary>
        /// <param name="unit"></param>
        /// <returns></returns>
        public Dictionary<int, List<ProductTempleteInfo>> GetAllShopProductTempleteList(string unit)
        {
            if (_shopProductTempleteList.Count < 1)
            {
                _shopProductTempleteList = _orderBLL.GetAllShopProductTempleteList(unit);
            }
            return _shopProductTempleteList;
        }


        /// <summary>
        /// 获取商户所勾选的产品模版
        /// </summary>
        /// <param name="shopId"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public List<ProductTempleteInfo> GetProductTempleteList(int shopId, string unit)
        {
            List<ProductTempleteInfo> productTempleteInfo = new List<ProductTempleteInfo>();
            if (_shopProductTempleteList.Keys.Contains(shopId))
            {
                productTempleteInfo = _shopProductTempleteList.First(s => s.Key == shopId).Value;
            }
            else
            {
                productTempleteInfo = _orderBLL.GetProductTempleteList(shopId, unit);
                _shopProductTempleteList.Add(shopId, productTempleteInfo);
            }

            return productTempleteInfo;
        }

        /// <summary>
        /// 获取所有有效商户
        /// </summary>
        /// <returns></returns>
       public   List<ShopInfo_Order> GetShopInfo()
        {
            if(_shopList.Count<1)
                _shopList = _orderBLL.GetShopList();
            return _shopList;
        }
    }
}
